import * as order from "../../api/order";

Page({
    data: {
        orderFundInfoVo:{},
        orderInfoVo:{},
        goodsSkuVoList:{},
        userReceiveAddressVo:{},
        orderExpressInfoVo:{},
        orderNo:""
    },
    onLoad(options){

        let expressRange = [];

        order.orderDetail({
            orderNo:options.orderNo
        })
            .then((res)=>{

                // let goodsItem = {
                //     goods:{
                //         goodsTitle: res.goodsSkuVoList[0].goodsTitle,
                //         goodsTitleShort: res.goodsSkuVoList[0].goodsTitleShort,
                //         standardName:res.goodsSkuVoList[0].standardName
                //     },
                //     sku:{
                //         skuImages:res.goodsSkuVoList[0].skuImages,
                //         skuPrice:res.goodsSkuVoList[0].skuPrice
                //     },
                //     skuNum:res.goodsSkuVoList[0].skuNum
                // }
                
                let expressWay = res.orderInfoVo.expressWay;
                let expressWayItem = expressRange.filter((el)=>{
                    return el.expressWayValue == expressWay;
                });

                console.log( res.goodsSkuVoList )

                res.orderInfoVo.expressWayLabel = expressWayItem.length>0 ? expressWayItem[0].expressWayLabel : "";
                
                this.setData({
                    orderFundInfoVo:res.orderFundInfoVo,
                    orderInfoVo:res.orderInfoVo,
                    goodsSkuVoList:res.goodsSkuVoList,
                    // goodsItem:goodsItem,
                    orderExpressInfoVo:res.orderExpressInfoVo,
                    userReceiveAddressVo:res.userReceiveAddressVo,
                    orderNo:options.orderNo
                });

            })
    },
    handle_copy_text(){
        wx.setClipboardData({
            data: this.data.orderInfoVo.orderNo,
            success: (result)=>{
                
            }
        });
    },
    handle_copy_express(){
        wx.setClipboardData({
            data: this.data.orderExpressInfoVo.expressNo
        });
    },
    handle_pay_order(){

        wx.showLoading({
            title: "订单支付中...",
            mask: true
        });

        index.wxPay({
            orderNo:this.data.orderNo
        })
            .then((res)=>{
                wx.requestPayment({
                    timeStamp: res.timeStamp,
                    nonceStr: res.nonceStr,
                    package: res.package,
                    signType: res.signType,
                    paySign: res.paySign,
                    success: (result)=>{ 
                        wx.hideLoading();
                        wx.navigateTo({
                            url: '/pages/pay-result/pay-result?orderNo='+this.data.orderInfoVo.orderNo
                        });
                    },
                    fail: (result)=>{
                        wx.hideLoading();
                    },
                    complete: ()=>{}
                });
            })
            .catch(()=>{
                wx.hideLoading();
            })
    }
})
